package com.stable.actor.messages;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 消息路由器 - 负责复杂的路由逻辑
 */
public class MessageRouter {
    private final Map<String, RouteRule> routeRules = new ConcurrentHashMap<>();

    /**
     * 添加路由规则
     */
    public void addRouteRule(String pattern, RouteRule rule) {
        routeRules.put(pattern, rule);
    }

    /**
     * 根据消息内容路由
     */
    public String routeByMessage(Object message) {
        if (message instanceof String) {
            String msg = (String) message;
            // 根据消息内容路由到不同的Actor
            if (msg.startsWith("order:")) {
                return "/user/orderProcessor";
            } else if (msg.startsWith("payment:")) {
                return "/user/paymentProcessor";
            }
        }
        return null;
    }
}

/**
 * 路由规则接口
 */
interface RouteRule {
    String getTargetPath(Object message);
}
